import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:meal/components/order/order_status.dart';
import 'package:meal/constant/antd_icons.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 未完成订单
///
class UnfinishedOrder extends StatefulWidget {
  const UnfinishedOrder({Key? key}) : super(key: key);

  @override
  State<UnfinishedOrder> createState() => _UnfinishedOrderState();
}

class _UnfinishedOrderState extends State<UnfinishedOrder>
    with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  bool oneself = false;

  late final TabController _controller;

  final List<String> tabs = ['待处理', '未取货', '配送中', '待审核', '全部'];

  @override
  void initState() {
    _controller = TabController(length: tabs.length, vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      backgroundColor: ColorsUtils.rgba(245, 245, 245),
      appBar: AppBar(
        backgroundColor: ColorsUtils.rgba(255, 110, 83, 1),
        elevation: 0,
        centerTitle: true,
        title: SizedBox(
          width: 200,
          height: 32,
          child: Row(
            children: [
              Expanded(
                  child: InkWell(
                onTap: () {
                  setState(() {
                    oneself = false;
                  });
                },
                child: Container(
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: oneself
                          ? ColorsUtils.rgba(252, 161, 144, 1)
                          : ColorsUtils.rgba(255, 255, 255, 1),
                      borderRadius: const BorderRadius.only(
                          topLeft: Radius.circular(16), bottomLeft: Radius.circular(16))),
                  child: Text(
                    '外卖配送',
                    style: StylesUtils.customTextStyle(
                      color: oneself ? ColorsUtils.colorFaf : ColorsUtils.colorFf6,
                    ),
                  ),
                ),
              )),
              Expanded(
                  child: InkWell(
                onTap: () {
                  setState(() {
                    oneself = true;
                  });
                },
                child: Container(
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: !oneself
                          ? ColorsUtils.rgba(252, 161, 144, 1)
                          : ColorsUtils.rgba(255, 255, 255, 1),
                      borderRadius: const BorderRadius.only(
                          topRight: Radius.circular(16), bottomRight: Radius.circular(16))),
                  child: Text('到点自取',
                      style: StylesUtils.customTextStyle(
                        color: !oneself ? ColorsUtils.colorFaf : ColorsUtils.colorFf6,
                      )),
                ),
              ))
            ],
          ),
        ),
        actions: [
          IconButton(
              icon: const Icon(
                AntdIcons.search,
                color: Colors.white,
              ),
              iconSize: Sizes.default18,
              onPressed: () {
                Get.toNamed(RouteGet.search);
              }),
        ],
        bottom: PreferredSize(
            preferredSize: Size(Get.width, 50),
            child: Container(
              color: Colors.white,
              alignment: Alignment.center,
              child: ToolsUtils.getClientTabBar(tabs, _controller),
            )),
      ),
      body: TabBarView(
        controller: _controller,
        children: tabs
            .asMap()
            .map((key, value) => MapEntry(key, OrderStatus(status: key)))
            .values
            .toList(),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
